package system.company.base.Objects;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Transaction;
import org.hibernate.criterion.Example;
import system.company.actor.Ordinary_Staff.BaseHibernateDAO;

/**
 	* A data access object (DAO) providing persistence and search support for Object_Information entities.
 			* Transaction control of the save(), update() and delete() operations 
		can directly support Spring container-managed transactions or they can be augmented	to handle user-managed Spring transactions. 
		Each of these methods provides additional information for how to configure it for the desired type of transaction control. 	
	 * @see system.company.base.Objects.Object_Information
  * @author MyEclipse Persistence Tools 
 */

public class Object_InformationDAO extends BaseHibernateDAO  {
    private static final Log log = LogFactory.getLog(Object_InformationDAO.class);
	//property constants
	public static final String NAME = "name";
	public static final String SEX = "sex";
	public static final String BIRTHDATE = "birthdate";
	public static final String DEPARTMENT = "department";
	public static final String STATUS = "status";
	public static final String CELLPHONE = "cellphone";
	public static final String PHONE = "phone";
	public static final String ADDRESS = "address";
	public static final String EMAIL = "email";
	public static final String DEGREE = "degree";



    
    public void save(Object_Information transientInstance) {
        log.debug("saving Object_Information instance");
        try {
        	Transaction tran = getSession().getTransaction();
			tran.begin();
            getSession().save(transientInstance);

            tran.commit();
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }
    
	public void delete(Object_Information persistentInstance) {
        log.debug("deleting Object_Information instance");
        try {
        	Transaction tran = getSession().getTransaction();
			tran.begin();
            getSession().delete(persistentInstance);
            tran.commit();
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }
    
    public Object_Information findById( java.lang.String id) {
        log.debug("getting Object_Information instance with id: " + id);
        try {
            Object_Information instance = (Object_Information) getSession()
                    .get("system.company.base.Objects.Object_Information", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
    
    
    public List findByExample(Object_Information instance) {
        log.debug("finding Object_Information instance by example");
        try {
            List results = getSession()
                    .createCriteria("system.company.base.Objects.Object_Information")
                    .add(Example.create(instance))
            .list();
            log.debug("find by example successful, result size: " + results.size());
            return results;
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }    
    
    public List findByProperty(String propertyName, Object value) {
      log.debug("finding Object_Information instance with property: " + propertyName
            + ", value: " + value);
      try {
         String queryString = "from Object_Information as model where model." 
         						+ propertyName + "= ?";
         Query queryObject = getSession().createQuery(queryString);
		 queryObject.setParameter(0, value);
		 return queryObject.list();
      } catch (RuntimeException re) {
         log.error("find by property name failed", re);
         throw re;
      }
	}

	public List findByName(Object name
	) {
		return findByProperty(NAME, name
		);
	}
	
	public List findBySex(Object sex
	) {
		return findByProperty(SEX, sex
		);
	}
	
	public List findByBirthdate(Object birthdate
	) {
		return findByProperty(BIRTHDATE, birthdate
		);
	}
	
	public List findByDepartment(Object department
	) {
		return findByProperty(DEPARTMENT, department
		);
	}
	
	public List findByStatus(Object status
	) {
		return findByProperty(STATUS, status
		);
	}
	
	public List findByCellphone(Object cellphone
	) {
		return findByProperty(CELLPHONE, cellphone
		);
	}
	
	public List findByPhone(Object phone
	) {
		return findByProperty(PHONE, phone
		);
	}
	
	public List findByAddress(Object address
	) {
		return findByProperty(ADDRESS, address
		);
	}
	
	public List findByEmail(Object email
	) {
		return findByProperty(EMAIL, email
		);
	}
	
	public List findByDegree(Object degree
	) {
		return findByProperty(DEGREE, degree
		);
	}
	

	public List findAll() {
		log.debug("finding all Object_Information instances");
		try {
			String queryString = "from Object_Information";
	         Query queryObject = getSession().createQuery(queryString);
			 return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	
    public Object_Information merge(Object_Information detachedInstance) {
        log.debug("merging Object_Information instance");
        try {
            Object_Information result = (Object_Information) getSession()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(Object_Information instance) {
        log.debug("attaching dirty Object_Information instance");
        try {
            getSession().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    public void attachClean(Object_Information instance) {
        log.debug("attaching clean Object_Information instance");
        try {
            getSession().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
}